home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NOVA - For the NeXT Workstation
/
NOVA - For the NeXT Workstation.iso
/
Documents
/
NeXTAnswers
/
objc.776
< prev
next >
Wrap
Text File
|
1992-02-06
|
1KB
|
49 lines
{\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f3\fmodern Ohlfs;\f0\fswiss Helvetica;}
\paperw13040
\paperh10800
\margl120
\margr120
{\colortbl\red0\green0\blue0;}
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b0\i0\ul0\fs28 C++ new error handler\
\
Q: In C++, how can I override the error handler for the
\b new
\b0 operator? I can do this with other compilers, but it doesn't work with the NeXT C++ compiler.\
\
A: On the NeXT, you can override the error for the
\b new
\b0 operator in the following way. Define a routine, say,
\b newErrorHandler
\b0 :\
\f3\fs22\fc0 \
static void newErrorHandler()\
\{\
fprintf(stderr, "new: Failed to
\pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0 acquire
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\fc0 sufficient memory.");\
fflush(stderr);\
\}\
\
\f1\fs28 Then, somewhere in your initialization routines call
\b set_new_handler
\b0 :\
\f3\fs22 \
set_new_handler(newErrorHandler);\
\pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\fc0 \
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b\fs28\fc0 newErrorHandler
\b0 will be called whenever an error is encountered during the
\b new
\b0 operation.\
\
QA776\
\
Valid for 1.0\
Valid for 2.0\
\